﻿using System;
using System.Runtime.Serialization;
using Citi.Scheduler.Domain;

namespace Citi.Scheduler.Wcf.DataContracts
{
    [DataContract]
    public class RoutineExecutionDataContract
    {
        public RoutineExecutionDataContract(RoutineExecution routineExecution)
        {
            if (routineExecution == null) return;

            StartsOn = routineExecution.StartsOn;
            EndsOn = routineExecution.EndsOn;
            ScheduledDateTime = routineExecution.ScheduledDateTime;
            MachineHostname = routineExecution.Machine.HostName;
            RoutineId = routineExecution.RoutineId;
            RoutineName = routineExecution.Routine.Name;
            Tentatives = routineExecution.Tentatives;
            LastHistory = new RoutineExecutionHistoryDataContract(routineExecution.LastHistory);
            CustomerSLA = routineExecution.CustomerSLA;
        }

        public DateTime? StartsOn { get; set; }
        public DateTime? EndsOn { get; set; }
        public DateTime ScheduledDateTime { get; set; }
        public string MachineHostname { get; set; }
        public int RoutineId { get; set; }
        public string RoutineName { get; set; }
        public short Tentatives { get; set; }
        public RoutineExecutionHistoryDataContract LastHistory { get; set; }
        public TimeSpan? CustomerSLA { get; set; }
    }
}